<?php

include '../verifica_usuario.php';
include '../functions.php';
include '../functions_office.php';

header('Content-type: text/html; charset=UTF-8');

include("../mysqlconfig.inc");

if (isset($_REQUEST['query']) && $_REQUEST['query'] != "") {
    $q = mysql_real_escape_string($_REQUEST['query']);

    $sql = "SELECT nome FROM EMPRESAS where locate('$q',nome) > 0 order by locate('$q',nome) limit 20";
    $r = mysql_query($sql);
    if ($r) {
        echo '<ul>' . "\n";
        while ($l = mysql_fetch_array($r)) {
            $p = $l['nome'];
            $p = preg_replace('/(' . $q . ')/i', '<span style="font-weight:bold;">$1</span>', $p);
            echo "\t" . '<li id="autocomplete_' . $l['nome'] . '">' . utf8_encode($p) . '</li>' . "\n";
        }
        echo '</ul>';
    }
}
?>